<?php
class Contacto extends DBAModel {
	private $idContacto;
	private $idUsuario;
	public $nombre;
	public $apellidos;
	public $email;
	public $direccion;
	public $foto;
	
	// association with Telefono class
	public $telefono = array ();
	/**
	 * Obtiene los datos del email y los guarda como objetos
	 *
	 * @see DBAModel::get()
	 */
	protected function get($idContacto) {
		// si es distinto de vacio
		if ($idContacto != '') :
			// hacemos la query
			$this->query = "
		SELECT *
		FROM contactos
		WHERE idContactos = '$idContacto'
		";
			// obtenemos los resultados
			$this->get_results_from_query ();
		
		
		
		endif;
		if (count ( $this->rows ) == 1) {
			/*
			 * $this->apellidos = $this->rows[0]['Apellidos']; $this->direccion = $this->rows[0]['direccion']; $this->email = $this->rows[0]['emai']; $this->foto = $this->rows[0]['foto']; $this->nombre = $this->rows[0]['Nombre']; $this->idContacto = $this->rows[0]['idContactos']; $this->idUsuario = $this->rows[0]['idUsuario'];
			 */
			foreach ( $this->rows [0] as $propiedad => $valor ) {
				$this->$propiedad = $valor;
			}
		} else {
			die ( "Usuario no encontrado" );
		}
	}
	
	public function set($array_datos) {
		if (array_key_exists ( 'email', $user_data )) :
			$this->get ( $user_data ['email'] );
			if ($user_data ['email'] != $this->email) :
				foreach ( $user_data as $campo => $valor ) :
					$$campo = $valor;
				endforeach
				;
				$this->query = "
		INSERT INTO usuarios
		(nombre, apellido, email, clave)
		VALUES
		('$nombre', '$apellido', '$email', '$clave')
		";
				$this->execute_single_query ();
			
			
		endif;
		
		
		endif;
	}
	public function edit($array_datos) {
		foreach ( $user_data as $campo => $valor ) :
			$$campo = $valor;
		endforeach
		;
		$this->query = "
		UPDATE usuarios
		SET nombre='$nombre',
		apellido='$apellido',
		clave='$clave'
		WHERE email = '$email'
		";
		$this->execute_single_query ();
	}
	public function delete($id) {
		$this->query = "
		DELETE FROM usuarios
		WHERE email = '$user_email'
		";
		$this->execute_single_query ();
	}
}

?>
